<template>
  <div class="newsinfo-container">
    <!-- 大标题 -->
    <h2 class="title">{{ newsinfo.title }}</h2>
    <!-- 子标题 -->
    <p class="subtitle">
      <span>发表时间：{{ newsinfo.add_time }}</span>
      <span>点击：{{ newsinfo.click }}次</span>
    </p>
    <hr />
    <!-- 内容区域 -->
    <div class="content" v-html="newsinfo.content"></div>
    <!-- 评论子组件 -->
    <comment :id="this.id"></comment>
  </div>
</template>

<script>
import axios from 'axios'
import { Toast } from 'mint-ui'
import comment from '../subcomponents/Comments.vue'

export default {
  components: {
    comment
  },
  data() {
    return {
      // id: this.$route.query.id
      id: this.$route.params.id, //把传递的id保存到data上方便以后调用
      newsinfo: {} //新闻资讯
    }
  },
  created() {
    this.getNewsInfo()
  },
  methods: {
    getNewsInfo() {
      //获取新闻资讯数据
      axios.get('/api/getnew/' + this.id).then(res => {
        // console.log(res.data)
        if (res.data.status === 0) {
          this.newsinfo = res.data.message[0]
          // Toast('获取新闻资讯数据成功...')
        } else {
          Toast('获取新闻资讯数据失败...')
        }
      })
    }
  }
}
</script>

<style lang="scss">
.newsinfo-container {
  padding: 0 5px;
  .title {
    color: red;
    text-align: center;
    font-size: 16px;
    margin: 15px 0;
  }
  .subtitle {
    font-size: 13px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
}
</style>
